//
//  AppDelegate.m
//  wawaji_ios
//
//  Created by yiguo qi on 2017/11/29.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "AppDelegate.h"
#import "UIColor+Utility.h"
#import <WXApi.h>
#import <Bugly/Bugly.h>
#import "QYGRootVC.h"

@interface AppDelegate ()<WXApiDelegate>

@property (nonatomic, strong) SGUtil *util;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    // 微信注册
    [WXApi registerApp:WXAppID];
    
    [self setRootVc:[[QYGRootVC alloc] init]];
    // 配置
    [self setUpGlobalConfiguration];
    // 崩溃日志
     [Bugly startWithAppId:TXbuglyID];
    return YES;
}
- (void)setUpGlobalConfiguration{
    // 键盘
    [self configureKeyboardManager];
    // 状态栏
    [self setupStatusBar];
    [self setUpSVProgress];
}
#pragma mark － 配置KeyboardManager
- (void)configureKeyboardManager {
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;
    manager.shouldToolbarUsesTextFieldTintColor = YES;
    manager.enableAutoToolbar = NO;
    
}
-  (void)setUpSVProgress{
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setCornerRadius:5.0];
    [SVProgressHUD setMinimumDismissTimeInterval:2];
}
#pragma mark－  状态栏
- (void)setupStatusBar
{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}


- (void)setRootVc:(UIViewController *)vc{
  
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [WXApi handleOpenURL:url delegate:[SGUtil shareUtil]];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
    return [WXApi handleOpenURL:url delegate:[SGUtil shareUtil]];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    [[NSNotificationCenter defaultCenter] postNotificationName:AppGoBackgroud object:nil];
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    [SVProgressHUD dismiss];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [[NSNotificationCenter defaultCenter] postNotificationName:AppGoForegroud object:nil];
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (SGUtil *)util {
    if(!_util){
        _util = [SGUtil shareUtil];
    }
    return _util;
}
@end
